package editor.cn;
class Solution714{
    public static void main(String[] args) {
        Solution solution = new Solution714().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int maxProfit(int[] prices, int fee) {
        int n=prices.length;
        int[][] dp = new int[n+1][2];//dp[i][1]定义为在第i天持有股票的最大利润，dp[i][0定义为在第i天持有股票的最大利润]
        dp[0][1]=Integer.MIN_VALUE/2;
        for (int i = 0; i < n ; i++) {
            dp[i+1][0]=Math.max(dp[i][0],dp[i][1]+prices[i]-fee);//核心点就在这里，我卖出的时候，就减去手术费，取最值就好。真的很妙！！
            dp[i+1][1]=Math.max(dp[i][1],dp[i][0]-prices[i]);
        }
        return dp[n][0];
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}












